import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Cookies from "vue-cookies"
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta:{
      Name:"/"
    },
    children:[
      {
        path: '/',
        name: 'HomeL',
        component: () => import('../components/Home/HomeL.vue'),
        meta:{
          Name:"/"
        },
        children:[
          {
            path: '/',
            name: 'HomeA',
            component: () => import('../components/Home/HomeA.vue'),
            meta:{
              Name:"/"
            },
          },
          {
            path: '/home/photo',
            name: 'Photo',
            component: () => import('../components/Home/Photo.vue'),
            meta:{
              Name:"/"
            },
          },
          {
            path: '/home/malllist',
            name: 'MallList',
            component: () => import('../components/Home/MallList.vue'),
            meta:{
              Name:"/"
            },
          },
        ]
      },
      {
        path: '/mall',
        name: 'Mall',
        component: () => import('../components/Mall/Mall.vue')
      },
      {
        path: '/order',
        name: 'Order',
        component: () => import('../components/Order/Order.vue')
      },
    ]
  },

  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  let Token = Cookies.get("token");
  if(to.name === "Login"){
    next();
  }else if(Token){
    next();
  }else{
    next("/login");
  }
})
export default router
